import ecs100.UI;
import java.util.ArrayList;
import java.util.Arrays;

public class Java_Review {
    public static void controlReview(){
        boolean isRaining = UI.askBoolean("今天下雨么？");

        if(isRaining){
            UI.println("在家躺着");
        }else{
            UI.println("出去吃饭");
        }

        boolean isFinishingHomework = UI.askBoolean("作业做完了么？");
        while (!isFinishingHomework){
            UI.println("做作业中...");
            isFinishingHomework = UI.askBoolean("作业做完了么？");
        }
        UI.println("可以玩了");

        if(isRaining){
            UI.println("只能在家玩了");
        } else{
            UI.println("出去玩");
        }
    }

    public static void arrayReview(){
        int[] nums1 = new int[100];  //生成一个含有100个整数的nums数组，初始值为0
        int[] nums2 = {1, 2, 3, 4, 5};  //基本类型数组还能直接 显式 的生成

        //更多的基本类型数组
        boolean[] b1 = new boolean[20];
        boolean[] b2 = {true, false, false, false, true};
        float[] f = {1.2f, 2.3f, 3.4f, 4.5f, 5.6f};
        double[] d = {2.2, 3.3, 4.4, 5.5, 6.6};

        //读取数组的长度（元素数量）
        int len = nums1.length;
        UI.println("nums1中有元素"+len+"个");

        //利用for循环遍历数组
        for(int i = 0; i < nums1.length; i++){
            nums1[i] += i;
        }
        //另外一种for循环遍历数组的用法
        for(int num : nums1){
            UI.print(num+" ");
        }
        UI.print('\n');

        //二维数组的三种声明方式。
        int[][] twoDArray1 = {{1,2,3},
                             {4,5,6},
                             {7,8,9}};
        int[][] twoDArray2 = new int[10][10];
        int[][] twoDArray3 = new int[10][]; //由此可见，二重数组并不是必须成矩形，各行在列上可以层次不齐，但行数必须确认
        //访问二维数组
        UI.println("访问第2行第0列:"+twoDArray1[2][0]);
        UI.println("访问第1行第1列:"+twoDArray1[1][1]);
    }

    public static void arrayListReview(){
        Student[] nameList = new Student[60];   //初始情况60人的班级
        Student s = new Student(20, 70, 1.7, 2012000000, "XX", "BB");
        s.transfer("国际教育", "电子信息工程");   //新来了一名学生

        Student[] temp = new Student[61];
        System.arraycopy(nameList, 0, temp, 0, nameList.length);    //通过这个函数对namelist整体复制到temp
        temp[60] = s;   //加入新来的学生
        nameList = temp; //重新引用
        //由此可见，普通数组的插入操作比较复杂

        ArrayList<Student> nameListUpgrade = new ArrayList<>(Arrays.asList(nameList));//从普通数组升级为ArrayList
        nameListUpgrade.add(s); //直接插入新学生
        Student s1 = nameListUpgrade.get(5); //读取花名册中下标为5的学生

    }

    public static void main(String[] args) {
        UI.printf("%.2f", 539.0);
    }
}

class Student{
    //定义类的属性
    private int age;    //年龄
    private double weight;  //体重
    private double height;  //身高
    private final long ID;    //学号, final修饰符说明该值不会被改变
    private String college;     //院
    private String department;      //系

    //类的构造器，函数名同类名，无返回值
    public Student(int age, double weight, double height, long ID, String college, String department){
        this.age = age;
        this.weight = weight;
        this.height = height;
        this.ID = ID;
        this.college = college;
        this.department = department;
    }
    //实现类的行为（类可执行的动作)
    public void eat(){
        this.weight++;
    }

    public void doSport(){
        this.weight--;
    }
    //让调用这个方法的对象的院系改变为传入参数的院系
    public void transfer(String college, String department){
        this.college = college;
        this.department = department;
    }

    public double getBMI(){
        return this.weight / (this.height * this.height);
    }

    //用于封装的getter和setter，封装是为安全起见，避免传入离谱的参数，例如setAge中
    public long getID() {
        return ID;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if(age < 0 || age > 120){
            return; //age小于0或大于120时，通过return终止掉setAge
        }
        this.age = age;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }
}